﻿Imports System.Data.SqlClient
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Xml

Public Class DataProvider

    Private Shared infoserver As String = ""

    'Public Property CONSTR() As String
    '    Get
    '        Return infoserver
    '    End Get
    '    Set(ByVal value As String)
    '        infoserver = value
    '    End Set
    'End Property

    Public Shared Sub CreateConnectionStringFromXml(ByVal filename As String)
        Dim xmlDoc As XmlDocument = New XmlDocument
        xmlDoc.Load(filename)
        Dim nodes As XmlNodeList = xmlDoc.DocumentElement.ChildNodes
        For Each childNode As XmlNode In nodes
            infoserver = childNode.SelectSingleNode("info").InnerText
        Next
    End Sub

    Public Shared Function ConnectioData() As SqlConnection
        Dim strCn As String = infoserver  '"Server = (local); Database=QuanLyNhanSu; Integrated Security = true"
        'Dim strCn As String = "workstation id=QuanLyNhanSu.mssql.somee.com;packet size=4096;user id=quochung;pwd=39891664;data source=QuanLyNhanSu.mssql.somee.com;persist security info=False;initial catalog=QuanLyNhanSu"
        Dim cn As SqlConnection = New SqlConnection(strCn)
        cn.Close()
        Return cn
    End Function

    Public Shared Function CommandData(ByVal strCm As String, ByVal cn As SqlConnection) As SqlCommand

        Dim cmd As SqlCommand = New SqlCommand(strCm, cn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection.Open()
        Return cmd
    End Function

    Private Function CommandData() As SqlConnection
        Throw New NotImplementedException()
    End Function

End Class
